package cn.lsnu.common.interfacetools.interfaceentity;

import java.util.List;


/**
 * @Description 分页信息
 * @author  lin
 * @Datetime  2020/2/2 16:00
 */
public class Page<T> extends BasePort implements BasePage {
	
	private Integer count;
	
	private Integer pageNo;
	
	private Integer pageSize;

	private Integer offSet;

	private Integer pageTotal;

	private T entity;
	
	/**
	 * @Fields field:field:{todo}(json数组处理使用)
	 */
	private List<T> data;

	public Integer getCount() {
		return count;
	}

	public void setCount(Integer count) {
		this.count = count;
	}

	public Integer getPageNo() {
		pageNo = pageNo==null?0:pageNo;
		return pageNo;
	}

	public void setPageNo(Integer pageNo) {
		this.pageNo = pageNo;
	}

	public Integer getPageSize() {
		pageSize = pageSize == null?15:pageSize;
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public List<T> getData() {
		return data;
	}

	public void setData(List<T> data) {
		this.data = data;
	}

	public T getEntity() {
		return entity;
	}

	public void setEntity(T entity) {
		this.entity = entity;
	}

	public Integer getOffSet() {

		if(offSet != null){
			return offSet;
		}
		if(pageNo != null && pageSize != null){
			offSet = (pageNo - 1)* pageSize;
		}
		return offSet == null?0:offSet;
	}

	public void setOffSet(Integer offSet) {

		this.offSet = offSet;
	}

	public Integer getPageTotal() {
		if(count !=null && pageSize != null) {
			if(pageSize == 0)
				pageTotal = 0;
			else {
				double total = Math.ceil((double)count / (double)pageSize);
				pageTotal = (int) total;
			}
		}
		return pageTotal;
	}

	public void setPageTotal(Integer pageTotal) {
		this.pageTotal = pageTotal;
	}

	@Override
	public String toString() {
		return "Page{" +
				"count=" + count +
				", pageNo=" + pageNo +
				", pageSize=" + pageSize +
				", offSet=" + offSet +
				", entity=" + entity +
				", data=" + data +
				"} " + super.toString();
	}
}
